package com.pattern.demo.javaapi;

import java.util.Observable;

/**
 * @ClassName: WeatherData  气象台数据
 * @Description:
 * @Date: 2020/8/27 14:54
 * @Author: Song JinGen
 */
public class WeatherDataByJdk extends Observable {

    /**
     *  温度
     */
    private float temperature;

    /**
     * 湿度
     */
    private float humidity;

    /**
     *  压力
     */
    private float pressure;

    /**
     * 描述
     */
    private String msg;

    /**
     * 风力
     */
    private String wind;

    /**
     * 数据变动，通知所有观察者
     */
    public void measurementsChanged(){
        setChanged();
        notifyObservers();
    }

    /**
     * 为了方便测试使用，手动更改值的变化，观察消费者是否收到值的变化
     * @param temperature
     * @param humidity
     * @param pressure
     */
    public void setMeasurements(float temperature, float humidity, float pressure, String wind, String msg){
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        this.wind = wind;
        this.msg = msg;
        measurementsChanged();
    }

    public float getTemperature() {
        return temperature;
    }

    public float getHumidity() {
        return humidity;
    }

    public float getPressure() {
        return pressure;
    }

    public String getMsg() {
        return msg;
    }

    public String getWind() {
        return wind;
    }
}
